<?php
defined('OA_LIB_PATH') || define('OA_LIB_PATH', '/opt/op/OALib');

require_once 'PHPUnit/Framework.php';
require_once 'Log.php';
require_once OA_LIB_PATH . '/../OpenLib/open/models/OaJobLogModel.php';

class OaOperationLogModelTest extends PHPUnit_Framework_TestCase
{
    private $_logger;
    private $_model;
    
    protected function setUp()
    {
        $logger = Log::factory('console');
        $logger->setMask(Log::MAX(PEAR_LOG_DEBUG));
        $this->_logger = $logger;
        $this->_model = new OaJobLogModel($logger);
    }
    
    protected function tearDown()
    {
        
    }
    
    public function testGetRegLoginDataByArea()
    {
        //$this->markTestSkipped();
        $result = $this->_model->getJobStatus();
        $this->_logger->log($result, PEAR_LOG_DEBUG);
        $this->assertTrue(is_array($result));
        $result = $this->_model->getJobStatus(2);
        $this->_logger->log($result, PEAR_LOG_DEBUG);
        $this->assertTrue($result!=false);
        $where = array('app_id'=>123,'status'=>1);
        $result = $this->_model->getJobLog($where, 0, 5);
        $this->_logger->log($result, PEAR_LOG_DEBUG);
//        print_r($result);
        $this->assertTrue(is_array($result));
        $result = $this->_model->getJobLogCount($where);
        $this->_logger->log($result, PEAR_LOG_DEBUG);
        $this->assertTrue($result !== false);
    }
    public function testCreateOpLog()
    {
        $this->markTestSkipped();
//        $result = $this->_model->createJobLog(691497365, 23456, '127.0.0.1', array('app_id'=>123,'status'=>1, 'message'=>'lelelel', 'download_link'=>'http://'));
//        $this->_logger->log($result, PEAR_LOG_DEBUG);
//        $this->assertTrue($result!==false);
//        $result = $this->_model->createJobLog(691497365, 23456, '127.0.0.2', array('app_id'=>123,'status'=>1, 'message'=>'lelelel', 'download_link'=>'http://'),2);
//        $this->_logger->log($result, PEAR_LOG_DEBUG);
//        $this->assertTrue($result!==false);
        $where = array('app_id'=>123,'environment'=>1);
        $result = $this->_model->deleteJobLog($where);
        $this->_logger->log($result, PEAR_LOG_DEBUG);
        print_r($result);
        $this->assertTrue($result !== false);
    }
}